<%--
  Created by IntelliJ IDEA.
  User: 10330
  Date: 2021/7/6
  Time: 13:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div class="modal fade" id="regFormModal" role="dialog" aria-hidden="true" aria-labelledby="myModalLabel">
    <form role="form" id="regForm">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" aria-hidden="true" type="button"
                            data-dismiss="modal">×</button>
                    <h4 class="modal-title" id="myModalLabel" style="text-align: left">用户注册</h4>
                </div>
                <div class="modal-body" style="text-align: left">

                    <div class="form-group">
                        <label for="usernameReg">用户名</label><input type="text" class="form-control" name="usernameReg" id="usernameReg" />
                    </div>
                    <div class="form-group">
                        <label for="passwordReg">密码</label><input type="password" class="form-control" name="passwordReg" id="passwordReg" />
                    </div>
                    <div class="form-group">
                        <label for="passwordRegConfirm">确认密码</label><input type="password" class="form-control" name="passwordRegConfirm" id="passwordRegConfirm" />
                    </div>
                    <div class="form-group">
                        <label for="age">年龄</label><input type="text" class="form-control" name="age" id="age" />
                    </div>
                    <div class="form-group">
                        <label for="userSex"> 性别 </label>
                        <div class="radio" id="userSex">
                            <label>
                                <input type="radio" name="userSex" id="sex1" value="0" checked> 男
                            </label>
                            <label>
                                <input type="radio" name="userSex" id="sex2" value="1"> 女
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="email">邮箱</label><input type="text" class="form-control" name="email" id="email" />
                    </div>


                </div>
                <div class="modal-footer">

                    <button class="btn btn-primary" type="button" onclick="register()">注册</button>
                    <button class="btn btn-default" type="button" data-dismiss="modal">关闭窗口</button>

                </div>
            </div>
        </div>
    </form>
</div>

<script>

    function register(){

        $.post("${pageContext.request.contextPath}/home?action=register",$('#regForm').serialize(),
            function(result){
            alert(result);
                if(JSON.parse(result).reg===true){
                    window.location.href="${pageContext.request.contextPath}/home?action=index";
                }
                else{
                    $("#msgTitle").html("注册失败");
                    $("#msgBody").html(JSON.parse(result).msg);
                    // alert(result);
                    $("#msgModal").modal();
                }

            });
    }

    function logout(){
        window.location.href="${pageContext.request.contextPath}/home?action=logout";
    }

</script>